package com.qf.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.entity.TlCity;
import com.qf.entity.TlHotel;
import com.qf.mapper.CityMapper;
import com.qf.mapper.HotelMapper;
import com.qf.service.HotelService;
import com.qf.utils.Mycode;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HotelServiceImpl extends ServiceImpl<HotelMapper, TlHotel> implements HotelService {

    @Autowired(required = false)
    HotelMapper hotelMapper;
    @Autowired
    CityMapper cityMapper;
    /**
     * 通过城市查找对应的酒店
     *
     * @param cityId 当前城市的ID
     * @return list 当前城市下所有的酒店信息
     */
    @Override
    public ResultMsg findCitytoHotel(Integer cityId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("city_id", cityId);
        List list = super.list(queryWrapper);
        if (list == null)
            return ResultMsg.ERROR(Mycode.HOTELFIND_ERRO);

        return ResultMsg.SUCCESS(list);
    }

    /**
     * 该酒店的信息
     *
     * @param cityId  城市ID
     * @param hotelId 该城市下的该酒店ID
     * @return
     */
    @Override
    public ResultMsg findOneHotel(Integer cityId, Integer hotelId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("city_id", cityId);
        queryWrapper.eq("hotel_id", hotelId);
        TlHotel one = super.getOne(queryWrapper);
        TlCity tlCity = cityMapper.selectById(cityId);
        one.setCityName(tlCity.getCityName());
        if (one == null)
            return ResultMsg.ERROR(Mycode.HOTERITEM_ERRO);
        return ResultMsg.SUCCESS(one);
    }

    /**
     * 查询前20的酒店
     *
     * @return
     */
    @Override
    public ResultMsg findAll(int start,int end) {
        List<TlHotel> list = hotelMapper.findAll(start,end);
        if (list != null)
            return ResultMsg.SUCCESS(list);
        return ResultMsg.ERROR(Mycode.HOTELFIND_ERRO);
    }


}
